﻿#include "common.h"

// 保存主角信息
void saveProtagonist() {
	ofstream output("protagonist.txt");

	Protagonist* protagonist = getProtagonist();

	output << "name=" << (*protagonist).name << endl;
	output << "sex=" << (*protagonist).sex << endl;

	output.close();
}

// 存档
void saveStore() {
	saveProtagonist();
}

// 获取一行中的value信息
string getValueFromLine(string line) {
	auto tIndex = line.find('=');
	auto value = line.substr(tIndex + 1);
	return value;
}

// 初始化主角信息
void initProtagonist() {
	Protagonist* protagonist = getProtagonist();

	ifstream input("protagonist.txt");

	string line;

	getline(input, line);
	(*protagonist).name = getValueFromLine(line);

	getline(input, line);
	(*protagonist).sex = stoi(getValueFromLine(line));

	input.close();
}

// 初始化存储
void initStore() {
	initProtagonist();
}

